#include "stdafx.h"
#include "tango frenzy.h"


extern int numar_noduri;
extern nod* headref;
extern nod * headtango;
extern lista *first;

extern lista* vechifirst;
extern nod* vechiheadref;
extern nod *vechiheadtango;


nod * copyarbore(nod *root)
{
	nod *crt=NULL;
	if (!root) return NULL;
	crt=(nod*)malloc(sizeof(nod));
	crt->info=root->info;
	crt->isroot=root->isroot;
	crt->preferatstg=root->preferatstg;
	crt->preferatdreapta=root->preferatdreapta;
	crt->left=copyarbore(root->left);
	crt->right=copyarbore(root->right);
	return crt;
}

lista* copylista(lista *el)
{
	lista *crt=NULL;
	if(!el) return NULL;
	crt=(lista*)malloc(sizeof(lista));
	crt->nrelem=el->nrelem;
	crt->radacina=copyarbore(el->radacina);
	crt->next=copylista(el->next);
	return crt;
}

void copiere()
{
	vechiheadref=copyarbore(headref);
	vechiheadtango=copyarbore(headtango);
	vechifirst=copylista(first);
}


void aranjare_lista(lista *root1,lista *root2)
{
	nod * au;
	//int aux;
	if (root2==NULL) return;
	if (root1==NULL) return;
	if (root1->nrelem==root2->nrelem&&root1->radacina->info>root2->radacina->info)
	{
		au=root1->radacina;
		root1->radacina=root2->radacina;
		root2->radacina=au;
	}
	aranjare_lista(root1,root2->next);
	//if (root1->next) aranjare_lista(root1->next,root1->next->next);
}
